import redis
# redis = redis.Redis(host='127.0.0.1')
redis1 = redis.Redis(host='192.168.1.65', port=6379, decode_responses=True)
# 发布者订阅者
redis1.publish("workflow", "hello")
print(1221)


# import time
# from collections import defaultdict
#
# channels = defaultdict(dict)
#
#
# class Intermedia:
#     @classmethod
#     def broadcast(cls, channel, msg):
#         '''向特定订户广播消息'''
#         # print(channels)
#         for name, callback in channels[channel].items():
#             # print(name,callback)
#             callback({
#                 'channel': channel,
#                 'msg': msg,
#                 'name': name
#             })
#     @classmethod
#     def register(cls, channel, subscriber):
#         '''将订阅服务器注册到特定通道'''
#         channels[channel][subscriber.name] = subscriber.callback
#     @classmethod
#     def unregister(cls, channel, subscriber):
#         '''从特定频道注销订阅服务器'''
#         del channels[channel][subscriber.name]
#
#
# class Publisher:
#     @classmethod
#     def publish(self, channel, msg):
#         '''发布消息到特定的通道'''
#         Intermedia.broadcast(channel, msg)
#         # print(1222)
#
#
#
# # from .task_pub import Intermedia
#
#
# class Subscriber:
#     def __init__(self, name, callback=None):
#         self.name = name
#         self.callback = callback if callable(callback) else self.callback
#
#     def callback(self, msg):
#         '''当前订阅服务器的默认事件处理程序'''
#         # time.sleep(5)
#         print('订阅者: "{0[name]}" 收到消息: "{0[msg]}" 来自 管道: "{0[channel]}"'.format(msg))
#
#     def subscribe(self, channel):
#         '''从发布服务器订阅特定的通道'''
#         Intermedia.register(channel, self)
#
#     def unsubscribe(self, channel):
#         '''从发布服务器取消订阅特定的通道'''
#         Intermedia.unregister(channel, self)
#
#
# Subscriber("uid1").subscribe("td1")
#
# Publisher().publish("td1","hello")
